package com.socool;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.ListFragment;
import android.widget.Toast;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener;
import com.actionbarsherlock.view.Window;
import com.slidingmenu.lib.SlidingMenu;
import com.slidingmenu.lib.app.SlidingFragmentActivity;

public class BaseActivity extends SlidingFragmentActivity {

	
	protected ListFragment mFrag;
	
	private final Handler handler = new Handler();
	final static String LOG_TAG="test";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// ActionBar에 progress 추가
	//	requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
		
		// ActionBar 테마 세팅 (values/style.xml)
		setTheme(R.style.Theme_CustomActionBar);
		ActionBar actionBar = getSupportActionBar();
		
		// 액션바의 로고,배경,홈버튼 터치여부 설정
		//actionBar.setLogo(R.drawable.icon_menu);
		actionBar.setLogo(R.drawable.navi_grid);
	
		
		//actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_blue));
		actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_fb));
		
		actionBar.setDisplayHomeAsUpEnabled(true);
		actionBar.setDisplayShowTitleEnabled(true);
		
		
		// set the Behind View
		setBehindContentView(R.layout.menu_frame);
	
		
		FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
		mFrag = new SlideListFragment();
		t.replace(R.id.menu_frame, mFrag);
		t.commit();
		
		// SlidingMenu 세팅
		SlidingMenu sm = getSlidingMenu();
		sm.setShadowWidthRes(R.dimen.shadow_width);
		sm.setShadowDrawable(R.drawable.shadow);
		//sm.setShadowDrawable(R.drawable.popover_body);
		
		sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
		sm.setFadeDegree(0.35f);
		sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
		sm.setMode(SlidingMenu.LEFT);

		
		
	
		
	}
	

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getSupportMenuInflater().inflate(R.menu.main, menu);
		
/*
		
        // refresh아이콘 리스너 설정
        final MenuItem refresh = (MenuItem) menu.findItem(R.id.refresh);
        refresh.setOnMenuItemClickListener(new OnMenuItemClickListener() {
           // progress 표시
            public boolean onMenuItemClick(MenuItem item) {
                // item.setActionView(R.layout.progress_action);
                handler.postDelayed(new Runnable() {
                    public void run() {
                        refresh.setActionView(null);
                    }
                }, 1000);
                return false;
                
            }
        });
        
      */
		
		
		
		return true;
	}
	

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			toggle();
			return true;
		case R.id.menu_refresh:
			Toast.makeText(this, "Refresh Click", Toast.LENGTH_SHORT).show();
			 item.setActionView(R.layout.indeterminate_progress_action);
			 final MenuItem refresh = item;
			 handler.postDelayed(new Runnable() {
                 public void run() {
                     refresh.setActionView(null);
                 }
             }, 1000);
			 
			return true;
			
		case R.id.menu_exit:
			Builder d = new AlertDialog.Builder(this);
			d.setMessage("정말 종료하시겠어요?");
			d.setNegativeButton("예", new DialogInterface.OnClickListener() {
				
				public void onClick(DialogInterface dialog, int which) {
					// process전체 종료
					finish();
				}
			});
			d.setPositiveButton("아니요", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					dialog.cancel();
				}
			});
			
			d.show();
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	

}



/*
 * 
임의로 텍스트 색 변경
public void setTitle(String title){
	super.setTitle(Html.fromHtml("<font color='#ffffff'>"+title+"</font>"));
}
public void setTitle(int id){
	String title = getResources().getString(id);
	super.setTitle(Html.fromHtml("<font color='#ffffff'>"+title+"</font>"));
}

*/


/*	
레이아웃의 뷰 가져오기
LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final View layout = inflater.inflate(R.layout.textview, (ViewGroup)findViewById(R.id.LL_tab1));
*/
